from flask import Flask, render_template
import sqlite3

app = Flask(__name__)

@app.route('/')
def index():
    return render_template("index.html")

@app.route('/index')
def home():
    return render_template("index.html")

@app.route('/movie')
def movie():
    movies_list = []
    con = sqlite3.connect("movie.db")
    cur = con.cursor()
    sql = "select * from movie250"  # 数据库中表的名字
    data = cur.execute(sql)
    for item in data:
        movies_list.append(item)
    cur.close()
    con.close()
    return render_template("movie.html", movies=movies_list)

@app.route('/score')
def score():
    score_list = []
    num_list = []
    con = sqlite3.connect("movie.db")
    cur = con.cursor()
    sql = "select score,count(score) from movie250 group by score"
    data = cur.execute(sql)
    for item in data:
        score_list.append(item[0])
        num_list.append(item[1])
    cur.close()
    con.close()
    return render_template("score.html", score=score_list, num=num_list)

@app.route('/rated')
def rated():
    rated_list = []
    cname_list = []
    con = sqlite3.connect("movie.db")
    cur = con.cursor()
    sql = "select cname,rated from movie250"
    data = cur.execute(sql)
    for item in data:
        cname_list.append(item[0])
        rated_list.append(item[1])
    cur.close()
    con.close()
    return render_template("rated.html", rated=rated_list, cname=cname_list)

@app.route('/score1')
def score1():
    score1_list = []
    cname_list = []
    con = sqlite3.connect("movie.db")
    cur = con.cursor()
    sql = "select score,cname from movie250"
    data = cur.execute(sql)
    for item in data:
        score1_list.append(item[0])
        cname_list.append(item[1])
    cur.close()
    con.close()
    return render_template("score1.html", score1=score1_list, cname=cname_list)

@app.route('/name')
def name():
    score_list = []
    rated_list = []
    con = sqlite3.connect("movie.db")
    cur = con.cursor()
    sql = "SELECT score,rated FROM movie250  order by score desc  limit 15"
    data = cur.execute(sql)
    for item in data:
        score_list.append(item[0])
        rated_list.append(item[1])
    cur.close()
    con.close()
    return render_template("name.html", score=score_list, rated=rated_list)

@app.route('/word')
def word():
    return render_template("word.html")

@app.route('/team')
def team():
    return render_template("team.html")

if __name__ == '__main__':
    app.run()

